package com.aijle.videopaper.util;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;

public class SimpleWidgetManager implements IWidgetManager{
    ViewGroup mViewGroup;
    LinearLayout.LayoutParams mParams;

    public SimpleWidgetManager(Context context, ViewGroup viewGroup) {
        mViewGroup = viewGroup;
        mParams = new LinearLayout.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT );
        mParams.weight = 1.0f;
        mParams.gravity = Gravity.CENTER;
    }

    @Override
    public void addView(View view) {
        mViewGroup.addView(view, mParams);
    }

    @Override
    public void removeView(View view) {
        mViewGroup.removeView(view);
    }

    @Override
    public void updateLayout(View view, float alpha) {
//        mParams.alpha = alpha;
        if (view.getParent() == null) {
            mViewGroup.addView(view, mParams);
        } else {
            mViewGroup.updateViewLayout(view, mParams);
        }
    }
}
